/*
 * (C) 2014-2015 Alibaba Group Holding Limited
 *
 * This program is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License version 2 as
 * published by the Free Software Foundation.
 *
 *
 *     __  ___   ______        ___       __          ___
 *    |  |/  /  /  __  \      /   \     |  |        /   \
 *    |  '  /  |  |  |  |    /  ^  \    |  |       /  ^  \
 *    |    <   |  |  |  |   /  /_\  \   |  |      /  /_\  \
 *    |  .  \  |  `--'  |  /  _____  \  |  `----./  _____  \
 *    |__|\__\  \______/  /__/     \__\ |_______/__/     \__\
 *
 *
 *
 */
//
// Created by KOALA TEAM on 12/19/14.
//

#import "NSTimer+KLBlocks.h"

@interface NSObject (BlockInvoke)
-(void)tc_invoke:(NSTimer*)sender;
@end
@implementation NSObject (KLBlockInvoke)
-(void)tc_invoke:(NSTimer*)sender;
{
	void(^block)(NSTimer*) = (__bridge void (^)(NSTimer *__strong))((__bridge void*)self);
	block(sender);
}
@end

@implementation NSTimer (Blocks)
+ (NSTimer*)timerWithTimeInterval:(NSTimeInterval)ti repeats:(BOOL)yesOrNo block:(void(^)(NSTimer*))block;
{
	return [NSTimer timerWithTimeInterval:ti target:[block copy ] selector:@selector(tc_invoke:) userInfo:nil repeats:yesOrNo];
}
+ (NSTimer*)scheduledTimerWithTimeInterval:(NSTimeInterval)ti repeats:(BOOL)yesOrNo block:(void(^)(NSTimer*))block;
{
	return [NSTimer scheduledTimerWithTimeInterval:ti target:[block copy ] selector:@selector(tc_invoke:) userInfo:nil repeats:yesOrNo];
}
@end